package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.manager.service.ValidateCodeService;
import com.atguigu.spzx.model.dto.system.LoginDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.system.LoginVo;
import com.atguigu.spzx.model.vo.system.ValidateCodeVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2024-03-07-10:13
 */
@RestController
@Tag(name = "登录管理模块")
//@CrossOrigin(allowCredentials = "true",originPatterns = "*",allowedHeaders = "*")
@RequestMapping(value = "/admin/system/index")
public class IndexController {

    @Resource
    SysUserService sysUserService;

    @Autowired
    ValidateCodeService validateCodeService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto){
        LoginVo loginVo = sysUserService.login(loginDto);
        return Result.ok(loginVo);
    }

    @GetMapping("/generateValidateCode")
    public Result generateValidateCode(){
        ValidateCodeVo validateCodeVo = validateCodeService.generateValidateCode();
        return Result.ok(validateCodeVo);
    }

    @GetMapping("/getUserInfo")
    public Result getUserInfo(@RequestHeader String token){
        SysUser sysUser = sysUserService.getUserInfo(token);
        return Result.ok(sysUser);
    }

    @GetMapping("/logout")
    public Result logout(@RequestHeader String token){
        sysUserService.logout(token);
        return Result.ok();
    }




}
